package com.tang.transmission.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.tang.common.entity.liveVideo.LiveInfo;
import com.tang.transmission.mapper.LiveInfoMapper;
import com.tang.transmission.service.LiveInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 唐朝阳
 * @since 2022-05-17
 */
@Service
public class LiveInfoServiceImpl extends ServiceImpl<LiveInfoMapper, LiveInfo> implements LiveInfoService {
    @Autowired
    private LiveInfoMapper liveInfoMapper;

    @Override
    public PageInfo<LiveInfo> listLiveInfo(String keywords, Integer currentPage, Integer pageSize) {
            PageHelper.startPage(currentPage,pageSize);
            if (keywords == null || "".equals(keywords)) {
                QueryWrapper<LiveInfo> qw = new QueryWrapper<LiveInfo>();
                qw.eq("delete_flag",1);
                qw.orderByDesc("create_time");
                return PageInfo.of(liveInfoMapper.selectList(qw));
            }
            QueryWrapper<LiveInfo> queryWrapper = new QueryWrapper<LiveInfo>();
            queryWrapper.eq("delete_flag",1).orderByDesc("create_time").like("live_title",keywords);
            List<LiveInfo> lives = liveInfoMapper.selectList(queryWrapper);
            return  PageInfo.of(lives);
        }

    @Override
    public PageInfo<LiveInfo> listCompanyLive(String keywords, Integer currentPage, Integer pageSize, String companyName) {
        PageHelper.startPage(currentPage,pageSize);
        if (keywords == null || "".equals(keywords)) {
            QueryWrapper<LiveInfo> qw = new QueryWrapper<LiveInfo>();
            qw.eq("delete_flag",1);
            qw.eq("institutions",companyName);
            qw.orderByDesc("create_time");
            return PageInfo.of(liveInfoMapper.selectList(qw));
        }
        QueryWrapper<LiveInfo> queryWrapper = new QueryWrapper<LiveInfo>();
        queryWrapper.eq("delete_flag",1).orderByDesc("create_time").eq("institutions",companyName).like("live_title",keywords);
        List<LiveInfo> lives = liveInfoMapper.selectList(queryWrapper);
        return  PageInfo.of(lives);
    }
}
